     <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/common.css"/>

    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/main.css"/>

    <link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/css/my.css">

    <script type="text/javascript" src="__PUBLIC__/admin/js/libs/modernizr.min.js"></script>

	<script src="__PUBLIC__/home/js/jquery-2.1.1.min.js" type="text/javascript"></script>

    <script src="__PUBLIC__/layer/layer.js" type="text/javascript"></script>
 
  <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"><span class="crumb-step">&gt;</span><span>新增视频</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form action="" method="post" id="myform" name="myform" enctype="multipart/form-data">
                    <table class="insert-tab" width="100%">
                        <tbody>
                          
                            <tr>
                                <th><i class="require-red">*</i>标题：</th>
                                <td><input name="title" id="title" type="text" style="width:500px;"></td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>视频：</th>
                                <td><input name="smallimg" id="upload123" type="file"></td>
                            </tr>
							
							 <tr>
                                <th><i class="require-red">*</i>上传进度：</th>
                                <td>
								  <span id="progress"></span>
								  
								  <progress></progress>
								  
								</td>
                            </tr>
                          
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" onclick="upload()" type="button">
                                    <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                                </td>
                            </tr>
                        </tbody></table>
                </form>
            </div>
        </div>

    </div>

<script>

var type="";
  $(':file').change(function() {  
        var file = this.files[0]; //假设file标签没打开multiple属性，那么只取第一个文件就行了  
         
        type = file.type;  
       
    });  

function upload() {

  var arr1=type.split("/");
  
  var geshi=String(arr1[1]);
  
 

  if(geshi=="mp4" || geshi=="mov"){


var up1=$('#upload123').val();
var title=$('#title').val();

if(title==""){

 layer.msg('标题不能为空');return;

}


if(up1==""){

  layer.msg('你没有选择资源');return;

}


//创建FormData对象，初始化为form表单中的数据。需要添加其他数据可使用formData.append("property", "value");
var formData = new FormData($('form')[0]);
//ajax异步上传
$.ajax({
url: "{:U('Shangchuan/addnow')}",
type: "POST",
data: formData,
xhr: function(){ //获取ajaxSettings中的xhr对象，为它的upload属性绑定progress事件的处理函数
myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ //检查upload属性是否存在
//绑定progress事件的回调函数
myXhr.upload.addEventListener('progress',progressHandlingFunction, false);
}
return myXhr; //xhr对象返回给jQuery使用
},
success: function(result){

    if(result==1){
  
    layer.confirm('上传成功', {
	  btn: ['关闭','继续上传'] //按钮
	}, function(){
	  
	  layer.closeAll();
	  
	  
	}, function(){
	  
	  location.reload();
	  
	});

   }else{
   
     layer.alert('上传失败');
   
   }

},
contentType: false, //必须false才会自动加上正确的Content-Type
processData: false //必须false才会避开jQuery对 formdata 的默认处理
});

 }else{
  
    layer.msg('只能上传mp4 或者mov格式');return;
  
  }

}
//上传进度回调函数：
function progressHandlingFunction(e) {
if (e.lengthComputable) {
$('progress').attr({value : e.loaded, max : e.total}); //更新数据到进度条
var percent = e.loaded/e.total*100;
$('#progress').html(percent.toFixed(2) + "%");
if(percent==100){
 
    layer.msg('正在上传云盘,请勿刷新,时间因视频大小而不同', {
		  icon: 16
		  ,shade: 0.01,time:2000000000
		});
 
 
}
}
}
</script>

